package com.njtoyo.taxi.admin.rest.controller.marketing;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mapper.master.entity.CouponTemplate;
import com.njtoyo.taxi.admin.rest.presenter.marketing.CouponTemplateSimplePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.marketing.couponTemplate.CouponListWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.marketing.couponTemplate.CreateCouponWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.marketing.couponTemplate.UpdateCouponWrapper;
import com.njtoyo.taxi.admin.service.marketing.CouponTemplateService;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/marketing/coupon_template")
@Api(tags = "优惠券模板管理")
public class CouponTemplateController {
    @Autowired
    private CouponTemplateService couponTemplateService;

    @GetMapping("/all")
    @ApiOperation(value = "优惠券模板all列表")
    @ApiOperationSupport(order = 1)
    public RestResult<List<CouponTemplateSimplePresenter>> getAll() {
        return couponTemplateService.getAll();
    }

    @GetMapping("/list")
    @ApiOperation(value = "优惠券模板列表", notes = "优惠券模板列表,权限:coupon_template_list")
    @PermissionScope(names = {"coupon_template_list"})
    public RestResult<Page<CouponTemplate>> getList(@Valid CouponListWrapper couponListWrapper) {
        return couponTemplateService.getList(couponListWrapper);
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增优惠券模板", notes = "新增优惠券模板,权限:coupon_template_create")
    @PermissionScope(names = {"coupon_template_create"})
    public RestResult addCoupons(@Valid @RequestBody CreateCouponWrapper createCouponWrapper) {

        return couponTemplateService.addCoupons(createCouponWrapper);
    }

    @PatchMapping("/update/{id}")
    @ApiOperation(value = "修改优惠券模板", notes = "修改优惠券模板,权限:coupon_template_update")
    @PermissionScope(names = {"coupon_template_update"})
    public RestResult updateCoupons(@PathVariable("id") Long id, @Valid @RequestBody UpdateCouponWrapper updateCouponWrapper) {
        return couponTemplateService.updateCoupons(id, updateCouponWrapper);
    }
}
